<template>
    <div class="content-wrapper">
      <!-- Content Header (Page header) -->
      <section class="content-header">
        <h1>
          营销管理
        </h1>

        <ol class="breadcrumb">
          <li><a href="#"> 控制台</a></li>
          <li><a href="#">销售意向管理</a></li>
          <li class="active">指派</li>
        </ol>
      </section>

      <!-- Main content -->
      <section class="content">
          <div class="row">
            <div class="col-xs-12">
                <div class="box box-solid">
                    <div class="box-header with-border">
                      <h3 class="box-title">客户信息</h3>
                    </div>
                  <!-- /.box-header -->
                  <!-- form start -->
                  <form class="form-horizontal">
                    <div class="box-body">
                        <div class="row">
                            <div :class="['form-group', 'col-sm-6',{'has-error':errors.has('custom_name')}]">
                              <label class="col-sm-2 control-label">客户名称</label>
                              <div class="col-sm-10">
                                <input name="custom_name" class="form-control" v-model="custom_name" readonly>
                              </div>
                            </div>
                            <div :class="['form-group', 'col-sm-6',{'has-error':errors.has('contact_name')}]">
                              <label  class="col-sm-2 control-label">联系人</label>
                              <div class="col-sm-10">
                                <input class="form-control" name="contact_name" v-model="contact_name" readonly>
                              </div>
                            </div>
                        </div>
                        <div class="row">
                            <div :class="['form-group', 'col-sm-6',{'has-error':errors.has('contact_mobile')}]">
                              <label  class="col-sm-2 control-label">联系电话</label>
                              <div class="col-sm-10">
                                <input class="form-control" name="contact_mobile"  v-model="contact_mobile" readonly>
                              </div>
                            </div>
                            <div :class="['form-group', 'col-sm-6',{'has-error':errors.has('origin')}]">
                              <label class="col-sm-2 control-label">机会来源</label>
                              <div class="col-sm-10">
                                <input class="form-control" name="origin" v-model="origin" readonly>
                              </div>
                            </div>
                        </div>

                        <div class="row">
                            <div :class="['form-group', 'col-sm-6',{'has-error':errors.has('intention')}]">
                              <label class="col-sm-2 control-label">合作意向</label>
                              <div class="col-sm-10">
                                <input class="form-control" name="intention" v-model="intention" readonly>
                              </div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="form-group col-sm-6">
                              <label  class="col-sm-2 control-label">创建人</label>
                              <div class="col-sm-10">
                                <input class="form-control" v-model="user_name" readonly>
                              </div>
                            </div>

                            <div class="form-group col-sm-6">
                                <label  class="col-sm-2 control-label">创建时间</label>
                                <div class="col-sm-10">
                                  <input class="form-control" readonly v-model="created_at" readonly="">
                                </div>
                           </div>
                        </div>

                    </div>
                    <!-- /.box-body -->
                    <div class="box-footer">
                      <button type="button" class="btn btn-primary" @click="submit">保存</button>
                    </div>
                    <!-- /.box-footer -->
                  </form>
                </div>
              <!-- /.box -->
            </div>
          </div>


          <div class="row">
            <div class="col-xs-12">
                <div class="box box-solid">
                    <div class="box-header with-border">
                      <h3 class="box-title">指派客户经理</h3>
                    </div>
                  <!-- /.box-header -->
                  <!-- form start -->
                  <form class="form-horizontal">
                    <div class="box-body">
                        <div class="form-group">
                          <label  class="col-sm-2 control-label">客户经理</label>
                          <div class="col-sm-4">
                            <select class="form-control" v-model="assigned_user_id">
                                <option value="0">请选择</option>
                                <option v-for="user in custom_manager_list" :value="user.id">{{user.name}}</option>
                            </select>
                          </div>
                        </div>
                    </div>
                    <!-- /.box-body -->
                    <div class="box-footer">
                      <button type="button" class="btn btn-primary" @click="submit">保存</button>
                    </div>
                  </form>
                </div>
              <!-- /.box -->
            </div>
          </div>




      </section>
      <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
</template>

<script>

import SaleIntention from '@/modules/SaleIntention'
import User from '@/modules/User'
export default {
    mounted() {
        if(this.$route.params.id > 0){
            this.loadModel();
        }
    },

    data() {
        return {
            custom_name:'',
            contact_name:'',
            contact_mobile:'',
            origin:'',
            intention:'',
            user_name:'',
            created_at:'',
            custom_manager_list:[],
            assigned_user_id:0
        };
    },

    methods: {



        loadModel() {
            SaleIntention.show(this.$route.params.id)
            .then((response) => {
                var model = response.contents;
                this.custom_name = model.custom_name;
                this.contact_name = model.contact_name;
                this.contact_mobile = model.contact_mobile;
                this.origin = model.origin;
                this.intention = model.intention;
                this.created_at = model.created_at;
                this.user_name = model.user.name;

                return User.list({role_id:User.ROLE_CUSTOM_MANAGER});
            })
            .then((response) => {
                var model = response.contents;
                this.custom_manager_list = model.data;
            });
        },

        submit() {
            this.$validator.validateAll().then((result) => {
                SaleIntention.assignUser(this.$route.params.id,this.assigned_user_id)
                .then((response) => {
                    $.message('操作成功');
                    this.$router.push({name:'SaleIntentionIndex'});
                })
            });
        }
    },

    computed:{

    }
}
</script>

<style lang="css">
</style>
